package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;

public class Police implements KeyListener, FocusListener{

	@Override
	public void focusGained(FocusEvent e) {
		JTextField textField = (JTextField) e.getSource();
		textField.setText(null);
	}

	@Override
	public void focusLost(FocusEvent e) {
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		
	}

	@Override
	public void keyPressed(KeyEvent e) {
		JTextField textField = (JTextField) e.getSource();
		if (textField.getCaretPosition() >= 6) {
			textField.transferFocus();
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		
	}

}
